package com.jiazhong.text;


import java.util.Scanner;

public class Text01 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean flag=true;
        int sum1=0,sum2=0,sum;
        System.out.println("请输入年份");
        int year=sc.nextInt();
        System.out.println("请输入月份");
        int month=sc.nextInt();
        Text01 ps=new Text01();
        while(flag){
            //计算年距离
            for (int i=1900;i<=year-1;i++){
                if ((i%4==0&&i%100!=0)||i%400==0){
                    sum1=+366;
                }
                else
                    sum1+=365;
            }
            //计算月距离
            for (int i=1;i<=month-1;i++){
                int monthday=ps.Switch(i,year);
                sum2+=monthday;
            }
            sum=sum1+sum2;
            //获得输入的月份有多少天
            int monthday=ps.Switch(month,year);
            //计算这个月的第一天是周几
            int weekday=sum%7+1;


            //循环遍历日历
            //1.制作日历头,及空格
            System.out.println("一\t二\t三\t四\t五\t六\t天\t");
            int j;//j为空格控制
            for (j=1;j<=weekday-1;j++){
                System.out.print(" \t");
            }
            //2.循环出日期
            for (int k=1;k<=monthday;k++){
                System.out.print(k+"\t");
                if (weekday==7){
                    System.out.println();
                    weekday=1;
                }
                else
                    weekday++;
            }

            //程序控制
            System.out.println();
            System.out.println("是否继续进行程序?(1或0)");
            int fl=sc.nextInt();
            if (fl==1){
                System.out.println("请输入年份");
                year=sc.nextInt();
                System.out.println("请输入月份");
                month=sc.nextInt();
            }
            else break;
        }
    }
    public int Switch(int i, int year){
        int monthday=0;
        switch (i){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                monthday=31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                monthday=30;
                break;
            case 2:
                if ((year%4==0&&year%100!=0)||year%400==0)
                    monthday=29;
                else
                    monthday=28;
                break;
        }
        return monthday;
    }
}


